home *** CD-ROM | disk | FTP | other *** search
- {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- (c) TechInsite Pty. Ltd.
- PO Box 429, Abbotsford, Melbourne. 3067 Australia
- Phone: +61 3 9419 6456
- Fax: +61 3 9419 1682
- Web: www.techinsite.com.au
- EMail: peter_hinrichsen@techinsite.com.au
-
- Created: Jan 2000
-
- Notes: Dialog for editing a person's details and browsing their
- Addresses and EAddresses. This dialog is used as the LH
- pane of the main form and is controled by the TtiTreeViewPlus.
-
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
- unit FEditPerson;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Adrs_BOM, ComCtrls, tiListView, StdCtrls, FEditEAddress
- ,FEditAddress
- ;
-
- type
- TFormEditPerson = class(TForm)
- GroupBox1: TGroupBox;
- eLastName: TEdit;
- eFirstName: TEdit;
- eInitials: TEdit;
- cbTitle: TComboBox;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- GroupBox2: TGroupBox;
- GroupBox3: TGroupBox;
- LVAddress: TtiListView;
- GroupBox4: TGroupBox;
- mNotes: TMemo;
- LVEAddress: TtiListView;
- procedure eLastNameChange(Sender: TObject);
- procedure LVEAddressDelete(Sender: TObject);
- procedure LVEAddressEdit(Sender: TObject);
- procedure LVEAddressNew(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure LVEAddressFilterData(pData: TPersistent; var pbInclude: Boolean);
- procedure LVAddressEdit(Sender: TObject);
- procedure LVAddressNew(Sender: TObject);
- procedure LVAddressDelete(Sender: TObject);
- procedure FormShow(Sender: TObject);
- private
- FData : TPerson ;
- FTreeNode : TTreeNode;
- FEditEAddress : TFormEditEAddress ;
- FEditAddress : TFormEditAddress ;
- procedure SetData(const Value: TPersistent);
- function GetData : TPersistent;
- function GetValid: boolean;
- published
- // These published properties are required by the TtiTreeViewPlus
- property Data : TPersistent read GetData write SetData ;
- property TreeNode : TTreeNode read FTreeNode write FTreeNode ;
- property Valid : boolean read GetValid ;
- public
-
- end;
-
- implementation
- uses
- tiPerObjAbs
- ;
-
- {$R *.DFM}
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TFormEditPerson
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // Form's OnCreate event
- procedure TFormEditPerson.FormCreate(Sender: TObject);
- begin
- FEditEAddress := TFormEditEAddress.Create( nil ) ;
- FEditAddress := TFormEditAddress.Create( nil ) ;
- end ;
-
- // Form's OnDelete event
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.FormDestroy(Sender: TObject);
- begin
- FEditEAddress.Free ;
- FEditAddress.Free ;
- end ;
-
- // Form's OnShow event
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.FormShow(Sender: TObject);
- begin
- if FData.ObjectState = posCreate then
- eLastName.SetFocus ;
- end;
-
- // Data's Get method
- //------------------------------------------------------------------------------
- function TFormEditPerson.GetData: TPersistent;
- begin
- result := FData ;
- end;
-
- // Data's Set method. Write data to the appropriate GUI controls.
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.SetData(const Value: TPersistent);
- begin
- if Value = nil then begin
- FData := nil ;
- exit ; //=>
- end ;
-
- FData := Value as TPerson ;
-
- eLastName.Text := FData.LastName ;
- eFirstName.Text := FData.FirstName ;
- eInitials.Text := FData.Initials ;
- cbTitle.ItemIndex := cbTitle.Items.IndexOf( FData.Title ) ;
- mNotes.Lines.Text := FData.Notes ;
-
- LVEAddress.Data := FData.EAddressList.List ;
- LVAddress.Data := FData.AddressList.List ;
-
- end;
-
- // The LastName was changed, so change the treeNode's text
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.eLastNameChange(Sender: TObject);
- begin
- if FData = nil then
- exit ; //==>
- if FTreeNode = nil then
- exit ; //==>
- if not Valid then
- exit ; //==>
-
- FTreeNode.Text := FData.Caption ;
-
- end;
-
- // The form's Valid property is called by the TtiTreeViewPlus before allowing
- // the node to change. Form validation is performed here.
- //------------------------------------------------------------------------------
- function TFormEditPerson.GetValid: boolean;
- begin
- result := true ;
- if FData = nil then
- exit ; //==>
-
- // Has there been a change made ?
- if ( FData.LastName = eLastName.Text ) and
- ( FData.FirstName = eFirstName.Text ) and
- ( FData.Initials = eInitials.Text ) and
- ( FData.Title = cbTitle.Items[ cbTitle.ItemIndex ] ) and
- ( FData.Notes = mNotes.Lines.Text ) then
- exit ;
-
- // Check for a valid lastName
- if eLastName.Text = '' then begin
- MessageDlg( 'Please enter a last name',
- mtInformation,
- [mbOK], 0 ) ;
- eLastName.SetFocus ;
- result := false ;
- exit ; //==>
- end ;
-
- // Assign data from the form to the data object
- FData.LastName := eLastName.Text ;
- FData.FirstName := eFirstName.Text ;
- FData.Initials := eInitials.Text ;
- FData.Title := cbTitle.Items[ cbTitle.ItemIndex ] ;
-
- // This requires work, as it should be its own object
- FData.Notes := mNotes.Lines.Text ;
-
- // Set the data objects ObjectState property to reflect the change.
- //FData.ObjectState := posUpdate ;
- FData.Dirty := true ;
-
- end;
-
- // TitListViewPlus action to delete an e-address.
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.LVEAddressDelete(Sender: TObject);
- var
- lData : TEAddress ;
- begin
- if sender = nil then
- exit ;
- if TListItem( sender ).Data = nil then
- exit ;
-
- lData := TEAddress( TListItem( Sender ).Data ) ;
-
- if MessageDlg( 'Are you sure you want to delete <' +
- lData.EAdrsType + ' - ' +
- lData.Text + '> ?',
- mtConfirmation,
- [mbYes, mbNo],
- 0 ) = mrYes then begin
- lData.Deleted := true ;
- LVEAddress.Refresh ;
- end ;
- end;
-
- // TitListViewPlus action to edit an e-address
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.LVEAddressEdit(Sender: TObject);
- begin
-
- if sender = nil then
- exit ;
- if TListItem( sender ).Data = nil then
- exit ;
-
- // Sender is the data
- FEditEAddress.Data := TEAddress( TListItem( Sender ).Data ) ;
- if FEditEAddress.ShowModal = mrOK then begin
- FEditEAddress.Data.ObjectState := posUpdate ;
- LVEAddress.Refresh ;
- end ;
-
- end;
-
- // TtiListViewPlus action to create a new e-address
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.LVEAddressNew(Sender: TObject);
- begin
- FEditEAddress.Data := TEAddress.CreateNew ;
- if FEditEAddress.ShowModal = mrOK then begin
- FData.EAddressList.Add( FEditEAddress.Data ) ;
- FEditEAddress.Data.Owner := FData ;
- LVEAddress.Refresh ;
- end else
- FEditEAddress.Data.Free ;
- end ;
-
- // TtiListViewPlus on filter event to filter deleted e-addresses
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.LVEAddressFilterData(pData: TPersistent; var pbInclude: Boolean);
- begin
- pbInclude := not ( pData as TPerObjAbs ).Deleted ;
- end ;
-
- // TtiListViewPlus action to edit an address
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.LVAddressEdit(Sender: TObject);
- begin
- if sender = nil then
- exit ;
- if TListItem( sender ).Data = nil then
- exit ;
-
- // Sender is the data
- FEditAddress.Data := TAddress( TListItem( Sender ).Data ) ;
- if FEditAddress.ShowModal = mrOK then begin
- FEditAddress.Data.ObjectState := posUpdate ;
- LVEAddress.Refresh ;
- end ;
-
- end;
-
- // TtiListViewPlus action to insert a new address
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.LVAddressNew(Sender: TObject);
- begin
- FEditAddress.Data := TAddress.CreateNew ;
- if FEditAddress.ShowModal = mrOK then begin
- FData.AddressList.Add( FEditAddress.Data ) ;
- FEditAddress.Data.Owner := FData ;
- LVAddress.Refresh ;
- end else
- FEditAddress.Data.Free ;
- end;
-
- // TtiListViewPlus action to delete an address
- //------------------------------------------------------------------------------
- procedure TFormEditPerson.LVAddressDelete(Sender: TObject);
- var
- lData : TAddress ;
- begin
- if sender = nil then
- exit ;
- if TListItem( sender ).Data = nil then
- exit ;
-
- lData := TAddress( TListItem( Sender ).Data ) ;
-
- if MessageDlg( 'Are you sure you want to delete <' +
- lData.AdrsType + ' - ' +
- lData.Text + '> ?',
- mtConfirmation,
- [mbYes, mbNo],
- 0 ) = mrYes then begin
- lData.Deleted := true ;
- LVAddress.Refresh ;
- end ;
- end;
-
- end.
-